<?php
require_once("../../../config.inc.php");
require_once(SERVER_FS_ROOT."/app/_inc/include.php");
require_once(SERVER_FS_ROOT."/app/util/imex/_inc/importExport.func.php");

$errMsg = sxREQ('msg');

$sSQL = "SELECT m.module, m.description FROM  module m ORDER BY m.module";
$objSDAO->query($sSQL, "mp");
$aModZ = array();
while($row = $objSDAO->fetch("mp")) {
	$aModZ[$row['module']] = $row['module']." - ".$row['description'];
}
reset($aModZ);
$module = sxREQUEST('mod');
if($module==''){
	$module = sxVx($objUser->aSV,'menuPageList','mod');
	if($module==''){
		$module = key($aModZ);
	}
} 
$_REQUEST['mod'] = $module;
$objUser->aSV['menuPageList']['mod'] = $module;

if(sxREQUEST("mod")==''){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true)."&msg=".urlencode(_t("variabile 'mod' non passata")); 
	serverRedir($url);
}
if(sxREQUEST("reqtype") == "exp"){
	$errMsg .= genExp();		
}
$module = sxREQ("mod");
$sSQL = "SELECT mp.*, m.description AS descr_module 
		FROM module m
		LEFT JOIN menu_page mp ON m.module=mp.module
		WHERE m.module='$module' ORDER BY mp.menu_page";
$query = $objSDAO->query($sSQL, "mp");
$row = $objSDAO->fetch("mp");

$aOpz = array("kMenu"=>'pro.men');
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
	function genExp() {
		document.objFrm.reqtype.value = 'exp';
		document.objFrm.submit();
	}
</script>
<?
echo(bodyHTML($aOpz));
//output comandi
$aCmd = array(
					"exp"=>array("pag"=>"javascript:genExp();",
										"title"=>_t("export"),
										"text"=>_t("export"),'align'=>'L',
										"perm"=>"newmod"),
					"ins"=>array("pag"=>"menuPageIns.php?mod=$module",
										"title"=>_t("add menu page"),
										"text"=>_t("new page"),
										"perm"=>"newmenu"),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1),
										"perm"=>"")
					);
//output dei dati
echo("<form name=\"objFrm\" id=\"objFrm\" action='".$_SERVER['PHP_SELF']."' method=\"POST\" enctype=\"multipart/form-data\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"---\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"labl01\" width='20%'>"
			."<a class=\"labl01\" href=\"../modl/moduleView.php?mod=$module&xsn=".XSN."\">Module</a></td>"
			."<td class='text01' width='80%'>".getHtmlSelect('mod',$aModZ,'@REQ',$aOptCM)."</td></tr>");
echo "</table>\n";
$sCmd = (commandsHTML($aCmd));	
echo $sCmd;	
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr><td class=\"titl01\" colspan='6'>Menu page</td></tr>\n");
echo("<tr>" .
		"<td class=\"tabh01\" width=\"1%\">"._t('Page')."</td>" .
		"<td class=\"tabh01\" width=\"37%\">"._t('Description')."</td>" .
		"<td class=\"tabh01\" width=\"1%\">"._t('Start')."</td>" .
		"<td class=\"tabh01\" width=\"30%\">"._t('Called page')."</td>" .
		"<td class=\"tabh01\" width=\"29%\">"._t('Calling page')."</td>" .
		"<td class=\"tabh01\" width=\"1%\">"._t('Export')."</td>" .
	"</tr>\n");	
$numElem = $nn = 0;
while($row){
	if (!empty($row['menu_page'])){ 
		$numElem ++;
		echo(
			"<tr>\n" .
				"   <td class=\"text01\" valign='top' align='center'><a class=\"text01\" ".
					goToPag("menuPageView.php?mod=".$row["module"]."&menu_page=".$row["menu_page"]."&xsn=".XSN).
					" title=\""._t("View menu page")."\">".
					$row["menu_page"]."</a></td>\n" .
				"   <td class=\"text01\" valign='top'>".$row["description"]."</td>\n" .
				"   <td class=\"text01\" valign='top' align='center'>".(($row["start_page"]=='Y')?_t('yes'):_t('no'))."</td>" .
				"   <td class=\"text01\" valign='top'>".''."</td>\n" .
				"   <td class=\"text01\" valign='top'>".''."</td>\n" .
				"   <td class=\"text01\" valign='top' align='center'>\n".
				"       <input type='checkbox' name='exp_".++$nn."' value=\"".
								$row["module"]."@".$row["menu_page"]."\" class='text01'>\n".
				"   </td>\n" .
			"</tr>\n");
	}
	$row = $objSDAO->fetch("mp");
}
if($numElem == 0) {
	echo("<tr>" .
			"<td class=\"text01\" colspan=\"6\">"._t("No menu page")."</td>".
		"</tr>\n");
}
echo("</table>\n</form>\n");
echo $sCmd;
echo(footerHTML());
exit();

function genExp() {
	global $objUser;
	$aReqExp = array();
 	foreach($_REQUEST as $key=>$value) {
 		if(substr($key,0,4) == "exp_") {
  			$aReqExp[] = array('menu_page',$value);
  			$objUser->setHistoryVar(array($key=>''));
 		}
 	}
  	$objUser->setHistoryVar(array('reqtype'=>''));
	if (count($aReqExp) == 0) {
		return _t("No item selected");
	}
	//dbg_("aReqExp=".print_r($aReqExp,1));
	$errMsg = tabExport($aReqExp);
	return $errMsg;
}
